package com.abc.fast.server.user.service.handler;

import cn.hutool.extra.spring.SpringUtil;
import com.abc.fast.common.domain.entity.Log;
import com.abc.fast.common.utils.ip.AddressUtils;
import com.abc.fast.server.user.service.ILogService;

import java.util.TimerTask;

/**
 * 异步任务处理类
 * @Author LiJunXi
 * @Date 2024-03-04 14:18
 */
public class UserAsyncHandler {

    /**
     * 保存日志
     * @param log
     * @return
     */
    public static TimerTask saveLog(Log log) {
        return new TimerTask() {
            @Override
            public void run() {
                // 远程查询操作地点
                log.setRequestLocation(AddressUtils.getRealAddressByIP(log.getRequestIp()));
                SpringUtil.getBean(ILogService.class).saveLog(log);
            }
        };
    }

}
